<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Pay extends Model
{
    protected $table ='pay';
    public $timestamps = false;

        /*
         * 用户获取当天消费
         * uid,时间:年-月-日
        */
    public function GetDaySale($id,$time){
        $starttime = strtotime(date('Y-m-d',$time));
        $endtime = strtotime(date('Y-m-d',$time))+86400;
        $sale = $this->where('uid',$id)->whereBetween('pay_time',[$starttime,$endtime])->sum('money');
        return $sale;
    }

    public function AddSale($id,$direction,$sale){
        $data[$direction] =$sale;
        $data['update_time'] =strtotime('now');
        $add = $this->where('id',$id)->update($data);
        if($add){
            return true;
        }else{
            return false;
        }
    }
}
